import asyncio
import json
import traceback
import uuid
import aioredis

import settings
from db.redis.redis_service import RedisMemory
from common.log import logger

redis_memory = RedisMemory()


class SeatPlannerMsgChannel(object):
    seat_channel = "seat:msg_channel"
    planner_channel = "planner:msg_channel"

    def __init__(self):
        self.aio_redis = aioredis.Redis(host=settings.redis_host,
                                        port=settings.redis_port,
                                        db=settings.redis_db,
                                        password=settings.redis_pwd)

    async def publish_msg(self, channel, message):
        try:
            await self.aio_redis.publish(channel, message.to_json())
            logger.info(f"发送到{channel}一条消息,消息为{message.to_json()}")
        except Exception:
            logger.info(f"发送到{channel}消息异常,消息为{traceback.format_exc()}")

    async def handle_seat_channel_data(self, session_id, clients=None):
        """
        与坐席工作台交互的通道  处理坐席处理后的数据
        Args:
            clients: 与小助的socket连接

        Returns:

        """
        raise NotImplementedError

    async def handle_planner_channel_data(self, session_id, clients):
        """
        与坐席工作台交互的通道  处理小助发送的数据
        Args:
            clients: 坐席的连接

        Returns:

        """
        raise NotImplementedError
